#include "RecordWidget.h"

void RecordWidget::setup(QImage image, QString text) {
	//this->setContextMenuPolicy(Qt::CustomContextMenu);
	//QObject::connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),this, SLOT(ShowContextMenu(const QPoint &)));
	QVBoxLayout *layout = new QVBoxLayout;
	QLabel *label = new QLabel;
	my_image = image.copy();
	label->setPixmap(QPixmap::fromImage(my_image));
	label->setFixedSize(image.size());
	QLabel *label2 = new QLabel(text);
	layout->addWidget(label);
	layout->addWidget(label2);
	setLayout(layout);
	setFixedSize(image.width() + 20, image.height() + 50);
}

void RecordWidget::contextMenuEvent(QContextMenuEvent * event) {
	QMenu *menu = new QMenu;
	QAction *saveAction = new QAction("Save");
	QObject::connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
	menu->addAction(saveAction);
	menu->exec(QCursor::pos());
	event->accept();
}

void RecordWidget::save() {
	QString fileName = QFileDialog::getSaveFileName(this,
		tr("Save Image"),
		"",
		tr("PNG Files (*.png)"));
	if (!fileName.isNull())
	{
		my_image.save(fileName);
	}
	else
	{
		return;
	}
}
